package constant

import (
	"github.com/lab-online/pkg/errors"
	"github.com/lab-online/pkg/gen"
	"github.com/lab-online/pkg/resp"
)

const (
	baseReqErrorCode      = resp.CodeBadRequest + domainCode
	codeIsExecuting       = baseReqErrorCode + 0
	codeClassNotFound     = baseReqErrorCode + 1
	codeCourseLabNotFound = baseReqErrorCode + 2
	codeIsReviewing       = baseReqErrorCode + 3
	codeIsLocked          = baseReqErrorCode + 4
	codeNotInClass        = baseReqErrorCode + 5

	baseServerErrorCode = resp.CodeServerError + domainCode
	codeJSONPatchError  = baseServerErrorCode + 0
	codeJSONMarshal     = baseServerErrorCode + 1
)

var (
	RESTErrIsExecuting       = errors.NewRESTError(400, codeIsExecuting, "实验正在进行中")
	RESTErrClassNotFound     = errors.NewRESTError(400, codeClassNotFound, "班级不存在")
	RESTErrCourseLabNotFound = errors.NewRESTError(400, codeCourseLabNotFound, "课程实验不存在")
	RESTErrIsReviewing       = errors.NewRESTError(400, codeIsReviewing, "实验正在批阅中")
	RESTErrIsLocked          = errors.NewRESTError(400, codeIsLocked, "实验已锁定")
	RESTErrNotInClass        = errors.NewRESTError(400, codeNotInClass, "不在班级中")

	RESTErrJSONPatch   = errors.NewRESTError(500, codeJSONPatchError, "JSON 值修改错误")
	RESTErrJSONMarshal = errors.NewRESTError(500, codeJSONMarshal, "JSON 序列化错误")
)

func ErrCodeMap() gen.CodeMap {
	return gen.ParseCodeMapFromErrors(gen.ErrorMap{
		"MimoDecode": {
			RESTErrClassNotFound,
			RESTErrCourseLabNotFound,
			RESTErrIsReviewing,
			RESTErrIsLocked,
			RESTErrNotInClass,
		},
		"MimoPlot": {
			RESTErrIsExecuting,
			RESTErrClassNotFound,
			RESTErrCourseLabNotFound,
			RESTErrIsReviewing,
			RESTErrIsLocked,
			RESTErrNotInClass,
		},
	})
}
